home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 February: Tool Chest / Dev.CD Feb 94.toast / Tool Chest / Development Platforms / MPW Related / MPW Interfaces / PInterfaces / TextServices.p < prev    next >
Encoding:
Text File  |  1993-09-17  |  11.1 KB  |  318 lines  |  [TEXT/MPS ]

  1. {
  2.     File:        TextServices.p
  3.  
  4.     Copyright:    © 1983-1993 by Apple Computer, Inc.
  5.                 All rights reserved.
  6.  
  7.     Version:    System 7.1 for ETO #11
  8.     Created:    Tuesday, March 30, 1993 18:00
  9.  
  10. }
  11.  
  12. {$IFC UNDEFINED UsingIncludes}
  13. {$SETC UsingIncludes := 0}
  14. {$ENDC}
  15.  
  16. {$IFC NOT UsingIncludes}
  17.  UNIT TextServices;
  18.  INTERFACE
  19. {$ENDC}
  20.  
  21. {$IFC UNDEFINED UsingTextServices}
  22. {$SETC UsingTextServices := 1}
  23.  
  24. {$I+}
  25. {$SETC UsingTextServices := UsingIncludes}
  26. {$SETC UsingIncludes := 1}
  27. {$IFC UNDEFINED UsingTypes}
  28. {$I $$Shell(PInterfaces)Types.p}
  29. {$ENDC}
  30. {$IFC UNDEFINED UsingEvents}
  31. {$I $$Shell(PInterfaces)Events.p}
  32. {$ENDC}
  33. {$IFC UNDEFINED UsingMenus}
  34. {$I $$Shell(PInterfaces)Menus.p}
  35. {$ENDC}
  36. {$IFC UNDEFINED UsingAppleEvents}
  37. {$I $$Shell(PInterfaces)AppleEvents.p}
  38. {$ENDC}
  39. {$IFC UNDEFINED UsingErrors}
  40. {$I $$Shell(PInterfaces)Errors.p}
  41. {$ENDC}
  42. {$IFC UNDEFINED UsingComponents}
  43. {$I $$Shell(PInterfaces)Components.p}
  44. {$ENDC}
  45. {$SETC UsingIncludes := UsingTextServices}
  46.  
  47. CONST
  48.  
  49.     kTSMVersion            =    1;                        { Version of Text Services Manager }
  50.     kTextService        =    'tsvc';                    { Component type for component description }
  51.     kInputMethodService    =    'inpm';                    { Component subtype for component description }
  52.     
  53.     bTakeActiveEvent    =    15;                        { Bit set if the component takes activate events }
  54.     bScriptMask            =    $00007F00;                { Bits 8 - 14 }
  55.     bLanguageMask        =    $000000FF;                { Bits 0 - 7 }
  56.     bScriptLanguageMask    =    bScriptMask + bLanguageMask;    {Bits 0 - 14 }
  57.  
  58. { Hilite styles ... }
  59.     kCursorPosition                =    1;                { specify cursor position }
  60.     kRawText                    =    2;                { specify range of raw text }
  61.     kSelectedRawText            =    3;                { specify range of selected raw text }
  62.     kConvertedText                =    4;                { specify range of converted text }
  63.     kSelectedConvertedText        =    5;                { specify range of selected converted text }
  64.     
  65. {
  66.     Apple Event constants
  67. }
  68.  
  69.     kTextServiceClass        =    kTextService;        { Event class }
  70.     kUpdateActiveInputArea    =    'updt';                { Update the active inline area }
  71.     kPos2Offset                =    'p2st';                { Convert global coordinates to character position }
  72.     kOffset2Pos                =    'st2p';                { Convert character position to global coordinate }
  73.     kShowHideInputWindow    =    'shiw';                { show or hide the input window }
  74.     
  75.  
  76.     { Event keywords ... }
  77.  
  78.     keyAETSMDocumentRefcon    =    'refc';                { TSM document refcon }
  79.  
  80.     keyAEServerInstance    =    'srvi';                    { Server instance }
  81.     keyAETheData        =    'kdat';                    { typeText }
  82.     keyAEScriptTag        =    'sclg';                    { Script tag }
  83.     keyAEFixLength        =    'fixl';
  84.     keyAEHiliteRange    =    'hrng';                    { Hilite range array }
  85.     keyAEUpdateRange    =    'udng';                    { Update range array }
  86.     keyAEClauseOffsets    =    'clau';                    { Clause offsets array }
  87.     keyAECurrentPoint    =    'cpos';                    { Current point }
  88.     keyAEDragging        =    'bool';                    { Dragging flag }
  89.     keyAEOffset            =    'ofst';                    { Offset }
  90.     keyAERegionClass    =    'rgnc';                    { Region class }
  91.     keyAEPoint            =    'gpos';                    { Current point }
  92.     keyAEBufferSize        =    'buff';                    { Buffer size to get the text }
  93.     keyAERequestedType    =    'rtyp';                    { Requested text type }
  94.     keyAEMoveView        =    'mvvw';                    { Move view flag }
  95.     keyAELength            =    'leng';                    { Length }
  96.     keyAENextBody        =    'nxbd';                    { Next or previous body }
  97.  
  98. { optional keywords for Offset2Pos        -- 28Mar92 }
  99.  
  100.     keyAETextFont        =    'ktxf';
  101.     keyAETextPointSize    =    'ktps';
  102.     keyAETextLineHeight    =    'ktlh';
  103.     keyAETextLineAscent    =    'ktas';
  104.     keyAEAngle            =    'kang';
  105.     
  106. { optional keyword for Pos2Offset        }
  107.  
  108.     keyAELeftSide        =    'klef';                    { type Boolean }
  109.  
  110.  
  111. { optional keyword for kShowHideInputWindow    }
  112.  
  113.     keyAEShowHideInputWindow    =    'shiw';            { type Boolean }
  114.  
  115. { keyword for PinRange  }
  116.  
  117.     keyAEPinRange                =    'pnrg';            { <#6> }
  118.  
  119.  
  120. { Desc type ... }
  121.  
  122.     typeComponentInstance    =    'cmpi';                { Component instance }
  123.     typeTextRangeArray        =    'tray';                { Text range array }
  124.     typeOffsetArray            =    'ofay';                { Offset array }
  125.     typeIntlWritingCode        =    'intl';                { Script code }
  126.     typeQDPoint                =    'QDpt';                { QuickDraw point }
  127.     typeAEText                =    'tTXT';                { Apple Event text }
  128.     typeText                =    'TEXT';                { Plain text }
  129.     
  130.     typeTextRange            =    'txrn';                { <#6> }
  131.  
  132.  
  133. {
  134.     Error codes
  135. }
  136.  
  137.     tsmComponentNoErr    =    0;                        { Component result = no error }
  138.     
  139.     tsmUnsupScriptLanguageErr    =    -2500;
  140.     tsmInputMethodNotFoundErr    =    -2501;
  141.     tsmNotAnAppErr                =    -2502;            { Not an application error }
  142.     tsmAlreadyRegisteredErr        =    -2503;            { Attemp to register again }
  143.     tsmNeverRegisteredErr        =    -2504;            { App never registered.  (Not TSM Aware) }
  144.     tsmInvalidDocIDErr            =    -2505;            { Invalid TSM documentation ID }
  145.     tsmTSMDocBusyErr            =    -2506;            { Document is still active }
  146.     tsmDocNotActiveErr            =    -2507;            { Document is not active }
  147.     tsmNoOpenTSErr                =    -2508;            { No open text service }
  148.     tsmCantOpenComponentErr        =    -2509;            { Can’t open the component }
  149.     tsmTextServiceNotFoundErr    =    -2510;            { No text service found }
  150.     tsmDocumentOpenErr            =    -2511;            { There are open documents }
  151.     tsmUseInputWindowErr        =    -2512;            { Not TSM aware because an input window is being used }
  152.     tsmTSHasNoMenuErr            =    -2513;            { The Text Service has no menu }
  153.     tsmTSNotOpenErr                =    -2514;            { Text service is not open }
  154.     tsmComponentAlreadyOpenErr    =    -2515;            { Text service already open for document }
  155.  
  156.     tsmInputMethodIsOldErr        =    -2516;            { Returned by GetDefaultInputMethod }
  157.     tsmScriptHasNoIMErr            =    -2517;            { Script has no input method or is using old input method }
  158.     tsmUnsupportedTypeErr        =    -2518;            { unSupported interface type error }
  159.     tsmUnknownErr                =    -2519;            { Any other errors }
  160.  
  161.     kTSMOutsideOfBody            =    1;
  162.     kTSMInsideOfBody            =    2;
  163.     kTSMInsideOfActiveInputArea    =    3;
  164.     
  165.     kNextBody                    =    1;
  166.     kPreviousBody                =    2;
  167.     
  168.     errOffsetInvalid            =    -1800;
  169.     errOffsetIsOutsideOfView    =    -1801;
  170.     errTopOfDocument            =    -1810;
  171.     errTopOfBody                =    -1811;
  172.     errEndOfDocument            =    -1812;
  173.     errEndOfBody                =    -1813;
  174.     
  175. TYPE
  176.     TextRangeHandle    =    ^TextRangePtr;
  177.     TextRangePtr    =    ^TextRange;
  178.     TextRange        =    Record                            { typeTextRange }
  179.                             fStart:            Longint;
  180.                             fEnd:            Longint;
  181.                             fHiliteStyle:    Integer;
  182.                         End;
  183.                         
  184.     TextRangeArrayHandle    =    ^TextRangeArrayPtr;
  185.     TextRangeArrayPtr        =    ^TextRangeArray;
  186.     TextRangeArray            =    Record                    { typeTextRangeArray }
  187.                                     fNumOfRanges:    Integer;
  188.                                     fRange:            Array [0..0] of TextRange;
  189.                                 End;
  190.                                 
  191.     OffsetArrayHandle    =    ^OffsetArrayPtr;
  192.     OffsetArrayPtr        =    ^OffsetArray;
  193.     OffsetArray            =    Record                        { typeOffsetArray }
  194.                                 fNumOfOffsets:    Integer;
  195.                                 fOffset:        Array [0..0] of Longint;
  196.                             End;
  197.  
  198.  
  199.     TextServicesInfoPtr    =    ^TextServiceInfo;
  200.     TextServiceInfo        =    Record
  201.                                 fComponent:        Component;
  202.                                 fItemName:        Str255;
  203.                             End;
  204.                             
  205.     TextServiceListHandle    =    ^TextServiceListPtr;
  206.     TextServiceListPtr        =    ^TextServiceList;
  207.     TextServiceList            =    Record
  208.                                     fTextServiceCount:    Integer;
  209.                                     fServices:             Array [0..0] of TextServiceInfo;
  210.                                 End;
  211.                             
  212.     ScriptLanguageRecord    =    Record
  213.                                     fScript:    ScriptCode;
  214.                                     fLanguage:    LangCode;
  215.                                 End;
  216.                                 
  217.     ScriptLanguageSupportHandle    =    ^ScriptLanguageSupportPtr;
  218.     ScriptLanguageSupportPtr    =    ^ScriptLanguageSupport;
  219.     ScriptLanguageSupport        =    Record
  220.                                         fScriptLanguageCount:    Integer;
  221.                                         fScriptLanguageArray:    Array [0..0] of ScriptLanguageRecord;
  222.                                     End;
  223.  
  224.     InterfaceTypeList    =    Array [0..0] of OSType;
  225.     
  226.     TSMDocumentID        =    Ptr;
  227.     
  228. {
  229.     Text Services Routines
  230. }
  231.  
  232. Function NewTSMDocument(numOfInterface: Integer; supportedInterfaceTypes: InterfaceTypeList; VAR idocID: TSMDocumentID; refCon: Longint): OSErr;
  233.     INLINE $303C, $0000, $AA54;
  234. Function DeleteTSMDocument(idocID: TSMDocumentID): OSErr;
  235.     INLINE $303C, $0001, $AA54;
  236. Function ActivateTSMDocument(idocID: TSMDocumentID): OSErr;
  237.     INLINE $303C, $0002, $AA54;
  238. Function DeactivateTSMDocument(idocID: TSMDocumentID): OSErr;
  239.     INLINE $303C, $0003, $AA54;
  240. Function TSMEvent(VAR event: EventRecord): Boolean;
  241.     INLINE $303C, $0004, $AA54;
  242. Function TSMMenuSelect(menuResult: Longint): Boolean;
  243.     INLINE $303C, $0005, $AA54;
  244. Function SetTSMCursor(mousePos: Point): Boolean;
  245.     INLINE $303C, $0006, $AA54;
  246. Function FixTSMDocument(idocID: TSMDocumentID): OSErr;
  247.     INLINE $303C, $0007, $AA54;
  248. Function GetServiceList(numOfInterface: Integer; supportedInterfaceTypes: InterfaceTypeList; VAR serviceInfo: TextServiceListHandle; VAR seedValue: Longint): OSErr;
  249.     INLINE $303C, $0008, $AA54;
  250. Function OpenTextService(idocID: TSMDocumentID; aComponent: Component; VAR aComponentInstance: ComponentInstance): OSErr;
  251.     INLINE $303C, $0009, $AA54;
  252. Function CloseTextService(idocID: TSMDocumentID; aComponentInstance: ComponentInstance): OSErr;
  253.     INLINE $303C, $000A, $AA54;
  254.  
  255. Function SendAEFromTSMComponent(VAR theAppleEvent: AppleEvent; VAR reply: AppleEvent; sendMode: AESendMode; sendPriority: AESendPriority; timeOutInTicks: Longint; idleProc: IdleProcPtr; filterProc: EventFilterProcPtr): OSErr;
  256.     INLINE $303C, $000B, $AA54;
  257. Function InitTSMAwareApplication: OSErr;
  258.     INLINE $303C, $0014, $AA54;
  259. Function CloseTSMAwareApplication: OSErr;
  260.     INLINE $303C, $0015, $AA54;
  261.  
  262.  
  263. Function SetDefaultInputMethod(ts: Component; VAR slRecord: ScriptLanguageRecord): OSErr;
  264.     INLINE $303C, $000C, $AA54;
  265. Function GetDefaultInputMethod(VAR ts: Component; VAR slRecord: ScriptLanguageRecord): OSErr;
  266.     INLINE $303C, $000D, $AA54;
  267. Function SetTextServiceLanguage(VAR slRecord: ScriptLanguageRecord): OSErr;
  268.     INLINE $303C, $000E, $AA54;
  269. Function GetTextServiceLanguage(VAR slRecord: ScriptLanguageRecord): OSErr;
  270.     INLINE $303C, $000F, $AA54;
  271. Function UseInputWindow(idocID: TSMDocumentID; useWindow: Boolean): OSErr;
  272.     INLINE $303C, $0010, $AA54;
  273. Function NewServiceWindow(wStorage: Ptr; boundsRect: Rect; title: Str255; 
  274.     visible: Boolean; theProc: Integer; behind: WindowPtr; goAwayFlag: BOOLEAN;
  275.     ts: ComponentInstance; VAR window: WindowPtr): OSErr;
  276.     INLINE $303C, $0011, $AA54;
  277. Function CloseServiceWindow(window: WindowPtr): OSErr;
  278.     INLINE $303C, $0012, $AA54;
  279. Function GetFrontServiceWindow(VAR window: WindowPtr): OSErr;
  280.     INLINE $303C, $0013, $AA54;
  281. Function FindServiceWindow(thePoint: Point; VAR theWindow: WindowPtr): Integer;
  282.     INLINE $303C, $0017, $AA54;
  283.  
  284. {
  285.     Low level Text Services routines
  286. }
  287.  
  288. Function GetScriptLanguageSupport(ts: ComponentInstance; VAR scriptHandle: ScriptLanguageSupportHandle): ComponentResult;
  289.     INLINE $2F3C, $0400, $0001, $7000, $A82A;
  290. Function InitiateTextService(ts: ComponentInstance): ComponentResult;
  291.     INLINE $2F3C, $0000, $0002, $7000, $A82A;
  292. Function TerminateTextService(ts: ComponentInstance): ComponentResult;
  293.     INLINE $2F3C, $0000, $0003, $7000, $A82A;
  294. Function ActivateTextService(ts: ComponentInstance): ComponentResult;
  295.     INLINE $2F3C, $0000, $0004, $7000, $A82A;
  296. Function DeactivateTextService(ts: ComponentInstance): ComponentResult;
  297.     INLINE $2F3C, $0000, $0005, $7000, $A82A;
  298. Function TextServiceEvent(ts: ComponentInstance; numOfEvents: Integer; VAR event: EventRecord): ComponentResult;
  299.     INLINE $2F3C, $0000, $0006, $7000, $A82A;
  300. Function GetTextServiceMenu(ts: ComponentInstance; VAR serviceMenu: MenuHandle): ComponentResult;
  301.     INLINE $2F3C, $0000, $0007, $7000, $A82A;
  302. Function TextServiceMenuSelect(ts: ComponentInstance; serviceMenu: MenuHandle; item: Integer): ComponentResult;
  303.     INLINE $2F3C, $0000, $0008, $7000, $A82A;
  304. Function FixTextService(ts: ComponentInstance): ComponentResult;
  305.     INLINE $2F3C, $0000, $0009, $7000, $A82A;
  306. Function SetTextServiceCursor(ts: ComponentInstance; mousePos: Point): ComponentResult;
  307.     INLINE $2F3C, $0000, $000A, $7000, $A82A;
  308. Function HidePaletteWindows(ts: ComponentInstance): ComponentResult;
  309.     INLINE $2F3C, $0000, $000B, $7000, $A82A;
  310.  
  311.  
  312. {$ENDC} { UsingTextServices }
  313.  
  314. {$IFC NOT UsingIncludes}
  315.  END.
  316. {$ENDC}
  317.  
  318.